package com.example.gss.ServiceImpl;

import com.example.gss.entity.Scholarship;
import com.example.gss.mapper.ScholarshipMapper;
import com.example.gss.Service.ScholarshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ScholarshipServiceImpl implements ScholarshipService {

    @Autowired
    private ScholarshipMapper scholarshipMapper;

    @Override
    public List<Scholarship> getAll() {
        return scholarshipMapper.findAll();
    }

    @Override
    public Scholarship getById(String id) {
        return scholarshipMapper.findById(id);
    }

    @Override
    public int save(Scholarship scholarship) {
        if (scholarship.getScholarshipId() == null) {
            // 生成唯一ID（实际项目中可使用UUID或雪花算法）
            // scholarship.setScholarshipId(UUID.randomUUID().toString());
            return scholarshipMapper.insert(scholarship);
        } else {
            return scholarshipMapper.update(scholarship);
        }
    }

    @Override
    public int update(Scholarship scholarship) {
        return scholarshipMapper.update(scholarship);
    }

    @Override
    public int delete(String id) {
        return scholarshipMapper.delete(id);
    }

    @Override
    public List<Scholarship> getByYear(Integer year) {
        return scholarshipMapper.findByYear(year);
    }

    @Override
    public List<Scholarship> getByLevel(String level) {
        return scholarshipMapper.findByLevel(level);
    }
}